package com.edu.rpc.kafka.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MyWeatherListener {
    // 默认的监听是从消息队列最后一个消息开始拿。新消息进来，就拿新消息。
    @KafkaListener(topics = "TsingDao-weather", groupId = "boot3-02-rpc-group")
    public void onMessage(ConsumerRecord<String, String> message) {
        // 1.获取消息的各种详细信息
        System.out.println("接收到消息：" + message);

        log.info("key：{}", message.key());
        log.info("value：{}", message.value());
    }

//    @KafkaListener(groupId = "boot3-02-rpc-group2", topicPartitions = {
//            @TopicPartition(topic = "test",
//                    partitionOffsets = @PartitionOffset(partition = "0", initialOffset = "0"))
//    })
//    public void onMessage2(ConsumerRecord<String, String> message) {
//        System.out.println("onMessage2 收到消息" + message.key() + ":" + message.value());
//    }
}
